#include "LoadExpressionOperationNode.hpp"
#include "KnownExpressionNode.hpp"
#include "../Level5/Variable.hpp"
#include "FloatExpressionNode.hpp"
#include "IntegerExpressionNode.hpp"
#include "TypeExpressionNode.hpp"
Level4::ExpressionNode* Level4::LoadExpressionOperationNode::Optimize()
{
	/*auto pnode(expression->Optimize());
	if()*/
	if (!var->isBuildInType)
		return this;
	else if (var->known)
	{
		if (var->type.buildInType == decltype(var->type.buildInType)::Float4)
			return new Float4ExpressionNode(*(float*)var->value);
		else if (var->type.buildInType == decltype(var->type.buildInType)::Float8)
			return new Float8ExpressionNode(*(double*)var->value);
		else if (var->type.buildInType == decltype(var->type.buildInType)::UnsignedInteger8)
			return new UnsignedInteger8ExpressionNode(*(unsigned char*)var->value);
		else if (var->type.buildInType == decltype(var->type.buildInType)::SignedInteger8)
			return new SignedInteger8ExpressionNode(*(signed char*)var->value);
		else if (var->type.buildInType == decltype(var->type.buildInType)::UnsignedInteger16)
			return new UnsignedInteger16ExpressionNode(*(unsigned short*)var->value);
		else if (var->type.buildInType == decltype(var->type.buildInType)::SignedInteger16)
			return new SignedInteger16ExpressionNode(*(short*)var->value);
		else if (var->type.buildInType == decltype(var->type.buildInType)::UnsignedInteger32)
			return new UnsignedInteger32ExpressionNode(*(int*)var->value);
		else if (var->type.buildInType == decltype(var->type.buildInType)::SignedInteger32)
			return new SignedInteger32ExpressionNode(*(unsigned*)var->value);
		else if (var->type.buildInType == decltype(var->type.buildInType)::UnsignedInteger64)
			return new UnsignedInteger64ExpressionNode(*(unsigned __int64*)var->value);
		else if (var->type.buildInType == decltype(var->type.buildInType)::SignedInteger64)
			return new SignedInteger64ExpressionNode(*(__int64*)var->value);
	}
	else
		return this;
}